home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / grabst / set.c < prev    next >
C/C++ Source or Header  |  1990-03-06  |  2KB  |  98 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1986, 1988 Regents of the University of California
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /* set.c -- routines for set manipulations. */
  9.  
  10. #include "attribute.h"
  11. #include "digraph.h"
  12.  
  13. BOOL empty();
  14. BOOL equal();
  15.  
  16. BOOL empty(set)
  17. SET *set;
  18.   /* empty returns TRUE if set is empty. */
  19. {
  20.     int i;  /* counter */
  21.  
  22.     if (set->first == (MAXNODES - 1) && set->last == 0)
  23.     {
  24.         return(TRUE);
  25.     }
  26.  
  27.       /* otherwise, is FALSE, but check anyway (for now) */
  28.     for (i = 0; i < MAXBYTES; i++)
  29.     {
  30.         if (set->bytes[i])
  31.         {
  32.         return(FALSE);
  33.     }
  34.     }
  35.  
  36.       /* the following statement should never be reached */
  37.     return(TRUE);
  38. } /* empty */
  39.  
  40. BOOL equal(set1, set2)
  41. SET *set1, *set2;
  42.   /* equal returns TRUE if set1 and set2 have the same elements. */
  43. {
  44.     int i;   /* counter */
  45.  
  46.     if ((set1->first != set2->first) || (set1->last != set2->last))
  47.     {
  48.         return(FALSE);
  49.     }
  50.  
  51.     for (i = 0; i < MAXBYTES; i++)
  52.     {
  53.         if (set1->bytes[i] != set2->bytes[i])
  54.     {
  55.         return(FALSE);
  56.     }
  57.     }
  58.  
  59.     return(TRUE);
  60. } /* equal */
  61.  
  62. card(set)
  63. SET *set;
  64.   /* card returns the cardinality of set.  */
  65. {
  66.     int i;       /* each element */
  67.     int count;   /* counter */
  68.  
  69.     count = 0;
  70.  
  71.     each_element(set, i)
  72.     loop
  73.        count++;
  74.     endloop
  75.  
  76.     return(count);
  77. } /* card */
  78.  
  79. print_set_elements(set)
  80. SET *set;
  81.   /* print_set_elements prints the elements of a set */
  82. {
  83.     int i;
  84.  
  85.     printf("first = %d , last = %d\n", set->first, set->last);
  86.     printf("elements: ");
  87.  
  88.     for (i = 0; i < MAXNODES; i++)
  89.     {
  90.         if (in(set, i))
  91.     {
  92.         printf("%d ", i);
  93.     }
  94.     }
  95.  
  96.     printf("\n");
  97. } /* print_set_elements */
  98.